package com.ctl.szmd.szmd.feature_wm.ui.viewmodel

import androidx.lifecycle.liveData
import androidx.lifecycle.viewModelScope
import com.ctl.lib_common.utils.http.doFailure
import com.ctl.lib_common.utils.http.doSuccess
import com.ctl.szmd.szmd.feature_wm.data.repository.WmRepository
import com.ctl.szmd.szmd.feature_wm.ui.base.BaseWmViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

/**
 * created by : chentl
 * Date: 2020/07/30
 */
class WmWebViewModel(private val repository: WmRepository) : BaseWmViewModel() {

    fun getInfoVisitCountStatistics(visitTypeNum: Int, infoId: String) = viewModelScope.launch {
        repository.getInfoVisitCountStatistics(visitTypeNum, infoId)
    }

    @ExperimentalCoroutinesApi
    fun getInfoWebViewAttachmentList(
        path: String,
        map: MutableMap<String, String>
    ) = liveData {
        repository.getInfoWebViewAttachmentList(path, map)
            .collectLatest { result ->
                result.doSuccess {
                    emit(it.attachmentList)
                }
                result.doFailure {

                }

            }
    }
}